package com.xuxin.baby.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.xuxin.baby.bean.BannerBean;
import com.xuxin.baby.glide.GlideApp;
import com.xuxin.baby.network.Retrofit;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * Created by xu_xin
 * Created on 2020.08.04 0004
 * 轮播图
 */
public class ImageAdapter extends BannerAdapter<BannerBean.ResultBean.ItemsBean, ImageAdapter.BannerViewHolder> {

    public ImageAdapter(List<BannerBean.ResultBean.ItemsBean> data) {
        super(data);
    }

    @Override
    public ImageAdapter.BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new ImageAdapter.BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(ImageAdapter.BannerViewHolder holder, BannerBean.ResultBean.ItemsBean data, int position, int size) {
        /**
         * 加载图片
         */
        ImageView imageView = holder.imageView;
        String bannerImage = Retrofit.image_url + data.getAdvPic();
        LogUtils.e("轮播图_image = " + bannerImage);
        GlideApp.with(imageView).load(bannerImage).centerCrop().into(imageView);
    }

    public static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            this.imageView = view;
        }
    }
}